package cn.lzx.transaction.programme;

import cn.lzx.domain.Customer;
import cn.lzx.domain.CustomerJpaRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by lzx on 2016/12/9.
 */
@Service
public class CustomerServiceProgram {

    @Autowired
    private CustomerJpaRepository customerJpaRepository;


    public void buy(Long userId,Long price){
        Customer customer = customerJpaRepository.findOne(userId);
        Long remainder = customer.getMoney()-price;
        customer.setMoney(remainder);
        save(customer);
    }

    private void save(Customer customer){
        customerJpaRepository.save(customer);
    }
}
